/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-10-06 21:33:16
 * Last Modified: 2016-10-12 17:32:50
 * File Name: errorcode/errcode.go
 * Description:
 */
package errorcode

//全局错误码
const (
	EC_GL_SUCCESS uint = 0

	EC_GL_INVALID_ACCESS_TOKEN uint = 403001
	EC_GL_INVALID_APPKEY       uint = 403002
	EC_GL_INVALID_IP           uint = 403003
	EC_GL_INVALID_URL_TIME     uint = 403004
	EC_GL_INVALID_URL_SIGN     uint = 403005
	EC_GL_INVALID_ACCOUNT_TYPE uint = 403006
	EC_GL_INVALID_ACCOUNT_ID   uint = 403007
	EC_GL_INVALID_HTTPS        uint = 403008

	EC_GL_INVALID_JSON_BODY uint = 404001

	EC_GL_INTERNAL_ERROR uint = 503001
)

const (
	EC_REGISTER_MOBILE_REGISTED       uint = 201001 //手机注册时候,手机号已存在
	EC_REGISTER_MOBILE_NICKNAME_EMPTY uint = 201002 //手机注册时,昵称为空
	EC_REGISTER_MOBILE_PASSWORD_EMPTY uint = 201003 //手机注册时,密码为空
	EC_REGISTER_MOBILE_CAPTCHA_EMPTY  uint = 201004 //手机注册时,验证码为空
	EC_REGISTER_INVITECODE_WRONG      uint = 201005 //注册的邀请码不正确
	EC_REGLOGIN_OLDUSER_NOT_IN_APP    uint = 201006

	EC_ACCOUNT_BIND_BINDED_BY_OTHER            uint = 202001 //已被其他账号绑定
	EC_ACCOUNT_BIND_THIRD_INVALID_ACCOUNT_TYPE uint = 202002 //绑定第三方账号,但账号类型却非第三方账号类型
	EC_ACCOUNT_BIND_SELF_INVALID_ACCOUNT_TYPE  uint = 202003 //绑定自有账号,但账号类型不对
	EC_ACCOUNT_BIND_BINDED                     uint = 202004 //绑定的账号已经绑定过
	EC_ACCOUNT_BIND_MOBILE_WITHOUT_PASS        uint = 202005 //绑定手机号的时候没有密码
	EC_THIRDACCOUNT_BIND_MOBILE_ABORT          uint = 202006 //因为不同用户,无法绑定
	EC_MOBILE_CHANGE_CONFLICT                  uint = 202007 //更换手机号冲突

	EC_ACCOUNT_UNBIND_NOT_EXISTS     uint = 203001 //解绑的账号不存在
	EC_ACCOUNT_UNBIND_FORBIDDEN_SELF uint = 203002 //自有账号禁止解绑
	EC_ACCOUNT_UNBIND_FORBIDDEN_UNIQ uint = 203003 //唯一关联账号禁止解绑

	EC_CAPTCHA_INVALID_MOBILE_NUMBER uint = 204001 //非法或者格式不正确的手机号
	EC_CAPTCHA_NOT_SUPPORT_BID       uint = 204002 //不支持的短信验证码业务标识
	EC_CAPTCHA_TOO_FREQUENCE         uint = 204003 //发送间隔太频繁
	EC_CAPTCHA_REACH_LIMIT_TIMES     uint = 204004 //达到发送的限制次数
	EC_CAPTCHA_NOT_CORRECT           uint = 204005 //验证码不正确
	EC_CAPTCHA_NOT_EXISTS            uint = 204006 //验证码不存在

	EC_LOGIN_WITHOUT_PASSWD                  uint = 205001 //登录无密码
	EC_LOGIN_ACCOUNT_FREEZE                  uint = 205002 //账号冻结,禁止登录
	EC_LOGIN_ACCOUNT_NOT_EXISTS              uint = 205003 //账号不存在
	EC_LOGIN_INCORRECT_PASSWORD              uint = 205004 //登陆密码不对
	EC_LOGION_THIRD_ACCOUNT_NEED_BIND_MOBILE uint = 205005 //第三方登录需要绑定手机号

	EC_RESETPASS_ACCOUNT_NOT_EXISTS     uint = 206001 //重置密码时候,账号不存在
	EC_RESETPASS_ACCOUNT_FREEZE         uint = 206002 //重置密码时候,账号已被冻结
	EC_RESETPASS_REQUEST_IS_NULL        uint = 206003 //参数为空
	EC_RESETPASS_REQUEST_MOBILE_EMPTY   uint = 206004 //手机号为空
	EC_RESETPASS_REQUEST_CAPTCHA_EMPTY  uint = 206005 //验证码参数为空
	EC_RESETPASS_REQUEST_PASSWORD_EMPTY uint = 206006 //新密码为空
	EC_CHGPASS_REQUST_EMPTY             uint = 206007 //修改密码,请求参数为空
	EC_CHGPASS_OLD_PASSWD_EMPTY         uint = 206008 //修改密码,旧密码为空
	EC_CHGPASS_OLD_PASSWD_INCORRECT     uint = 206009 //修改密码,旧密码不正确
	EC_CHGPASS_NEW_PASSWD_EMPTY         uint = 206010 //修改密码,新密码为空

	EC_USERINFO_SET_NICKNAME_EMPTY     uint = 207001 //用户信息昵称为空
	EC_USERINFO_SET_NICKNAME_TOO_LONG  uint = 207002 //用户信息昵称太长
	EC_USERINFO_SET_GENDER_UNSUPPORT   uint = 207003 //用户信息性别错误,不支持
	EC_USERINFO_SET_SLOGAN_EMPTY       uint = 207004 //用户信息个性名称为空
	EC_USERINFO_SET_SLOGAN_TOO_LONG    uint = 207005 //用户信息个性签名太长
	EC_USERINFO_SET_BIRTHDAY_INCORRECT uint = 207006 //用户信息生日不正确
	EC_USERINFO_SET_AVATAR_EMPTY       uint = 207007 //用户信息头像地址为空
	EC_USERINFO_SET_AVATAR_TOO_LONG    uint = 207008 //用户信息头像地址太长
	EC_USERINFO_SET_AVATAR_NOT_SELFURL uint = 207009 //用户信息头像不允许自己设置
	EC_USERINFO_SET_REGIONCODE_EMPTY   uint = 207010 //用户地址行政区编码为空
	EC_USERINFO_SET_REGIONADDR_EMPTY   uint = 207011 //用户地址详细地址为空

	EC_AVATAR_BASE64_UPLOAD_REQUEST_NULL uint = 208001 //头像上传请求为空
	EC_AVATAR_BASE64_UPLOAD_EMPTY        uint = 208002 //头像内容为空
	EC_AVATAR_BASE64_UPLOAD_ERROR        uint = 208003 //上传失败
	EC_AVATAR_BASE64_UPLOAD_SAVING_ERROR uint = 208004 //上传保存的时候出错

	EC_ADMIN_DELETE_PASSPORT_ERROR uint = 209001 //删除账号信息出错

	//微信网页授权
	EC_AUTHORIZE_CONN_FAIL  uint = 210001 //授权调用微信接口失败
	EC_AUTHORIZE_ORTHER_ERR uint = 210002 //授权接口微信其他业务错误

)

var (
	errorMsg map[uint]string
)

func init() {
	errorMsg = make(map[uint]string)
	errorMsg[EC_GL_SUCCESS] = "success"

	errorMsg[EC_GL_INVALID_ACCESS_TOKEN] = "invalid access_token"
	errorMsg[EC_GL_INVALID_APPKEY] = "invalid appkey"
	errorMsg[EC_GL_INVALID_IP] = "Not allowed IP source"
	errorMsg[EC_GL_INVALID_URL_TIME] = "invalid url time"
	errorMsg[EC_GL_INVALID_URL_SIGN] = "invalid url sign"
	errorMsg[EC_GL_INVALID_ACCOUNT_TYPE] = "not support account type"
	errorMsg[EC_GL_INVALID_ACCOUNT_ID] = "empty accountid"
	errorMsg[EC_GL_INVALID_HTTPS] = "only https is allowed!"

	errorMsg[EC_GL_INVALID_JSON_BODY] = "invalid request josn body"

	errorMsg[EC_GL_INTERNAL_ERROR] = "internal server error"
}

func Msg(errcode uint) string {
	if msg, ok := errorMsg[errcode]; ok {
		return msg
	}
	return ""
}
